package com.geostar.constructionland.analyse.service.spatiaanalyst.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.geostar.constructionland.analyse.entity.Block;
import com.geostar.constructionland.analyse.entity.alyresult.tzhdlgdfx.AlyResultDlfx;
import com.geostar.constructionland.analyse.entity.model.AnalyseModel;
import com.geostar.constructionland.analyse.service.analyseresult.JysdFxDlfxService;
import com.geostar.constructionland.analyse.service.spatiaanalyst.SptAlyParamService;
import com.geostar.constructionland.common.entity.logs.mongolog.YzGeoJson;
import com.geostar.constructionland.common.global.ConstAnalyseType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author yelll
 * @since 2020-5-27 11:37
 * 毛面积分析
 **/
@Component
@Slf4j
public class MmjfxSptAnalyse extends NormalSptAnalyst{
    @Autowired
    SptAlyParamService sptAlyParamService;
    @Autowired
    JysdFxDlfxService jsydfxdlfxService;

    @Override
    public Map<String, Object> getQueryParam(AnalyseModel analyseModel) throws Exception{
        analyseModel.setFxlx(ConstAnalyseType.CONST_DLMJJFX);
        analyseModel.setFxlxMapped(ConstAnalyseType.CONST_DLMJJFX);
        analyseModel.setAnalyseVersion("1.0");
        analyseModel.setAdjustVersion ("1.0");
        /**毛面积分析*/
        /**查询目标地块，1）可调整为-1 2）地类为设施农用地 3）违法用地，不是已批红线且地类为建设用地*/
        List<Block> blocks = new ArrayList<>();
        List<AlyResultDlfx> alyResultDlfxes = jsydfxdlfxService.getMmjjsDlfxs(analyseModel.getAlyId());
        for(AlyResultDlfx alyResultDlfx : alyResultDlfxes){
            Block block = new Block();
            YzGeoJson yzGeoJson = alyResultDlfx.getYzGeoJson();
//            block.setDk_id(yzGeoJson.getId());
            block.setDk_id(alyResultDlfx.getDlid());
            block.setGeoJson(yzGeoJson.getGeoJson());
            blocks.add(block);
        }
        /**更新**/
        analyseModel.setBlocks(blocks);
        analyseModel.setDlnd("200912");
        /**确定接口参数构造类型**/
        Map<String,Object> requestInfo = sptAlyParamService.getCommonParam(analyseModel);
        Map<String,Object> param = new HashMap<>(1);
        try {
            param.put("requestInfo",objectMapper.writeValueAsString(requestInfo));
            log.info("requestInfo:"+objectMapper.writeValueAsString(requestInfo));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return param;
    }
}
